<%@ taglib uri="http://java.sun.com/jsp/jstl/core" 	prefix="c" %> 
<%@ taglib uri="http://displaytag.sf.net" 			prefix="display" %>
<%@ taglib uri="/struts-tags" 						prefix="s" %>

<link type="text/css" rel="stylesheet" href="js/jquery/css/ui-lightness/jquery-ui-1.8.16.custom.css"/>
<script type="text/javascript" src="js/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="styles/form-input.css" />
<link rel="stylesheet" type="text/css" href="styles/displaytag.css" />
<script type="text/javascript">
	$(document).ready(function() {
   		$("button").button();
 	});
		
	function CheckAll(fmobj) {
		for (var i=0;i<fmobj.elements.length;i++) {
			var e = fmobj.elements[i];
			if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
				e.checked = fmobj.allbox.checked;
			}
		}
	};
</script>

	<div class="error-text"><s:actionerror /></div>
	<div class="error-text"><s:fielderror /></div>
	<div class="message-text"><s:actionmessage /></div>
	
	<div>
		<h3>Maintain Region</h3>
		<s:form theme="simple" validate="true" method="POST" >
			<s:hidden name="regionId"/>
			<fieldset style="width:600px">
            	<legend><h3>Region</h3></legend>
           		<table cellpadding="3" class="table-form">
           			<s:if test="regionId==0L">
           				<tr><td>Region Code</td><td><s:textfield name="regionCode" maxlength="4"/>*</td></tr>
           			</s:if>
           			<s:else>
           				<s:hidden name="regionCode"/>
           				<tr><td>Region Code</td><td><s:textfield name="regionCode" readonly="true"/></td></tr>
           			</s:else>
					<tr><td>Region Name</td><td><s:textfield name="regionName" size="50"/>*</td></tr>
					<tr></tr>
	            	<s:if test="regionId==0L">
						<tr><td></td><td><s:submit type="button" action="addOrUpdateRegion">SAVE</s:submit></td></tr>
					</s:if>
					<s:else>
						<tr><td></td><td>
						<s:submit type="button" action="addOrUpdateRegion">UPDATE</s:submit>
						<button type="button" onclick="window.location.href='listRegion'">CANCEL</button>
					</s:else>
				</table>
			</fieldset>			
		</s:form>
	</div>
	<br>
	<br>
	<div>
		<s:form name="form_table" method="POST" theme="simple" action="removeRegions" onsubmit="return confirm('Delete these regions?');">
			<c:set var="checkAll">
	    		<input type="checkbox" name="allbox" onclick="CheckAll(document.form_table)" />
			</c:set>
			<display:table 	id			= "region"
	              			name       	= "${regions}"
	             			pagesize   	= "10" style="width: 600px"
	              			requestURI 	= "/listRegion" class="display" decorator="com.btpn.custody.web.m001.decorator.RegionDecorator">
	              	              	
	            <display:column title	= "${checkAll}"
	            				property= "checkbox" style="width: 10%" />
	              				
	   			<display:column title	= "NO." style="width: 10%"
	              				value   = "${region_rowNum}" />
	              			
	            <display:column title 	= "Region Code" style="width: 30%"
			   					nulls	= "false" sortable= "true" >
			   		<c:url var="urlEdit" value="editRegion">
						<c:param name="id" value="${region.id}"/>
					</c:url>
					<a href="${urlEdit}">${region.code}</a> 
			   	</display:column>
			   		   
			   	<display:column title 	= "Region Name" style="width: 40%"
			   					nulls	= "false" sortable= "true" >
			   		<c:url var="urlEdit" value="editRegion">
						<c:param name="id" value="${region.id}"/>
					</c:url>
					<a href="${urlEdit}">${region.name}</a> 
			   	</display:column>		
			</display:table>

			<c:if test="${regions.size()>0}" >
	          	<button type="submit" >DELETE</button>
	        </c:if>
		</s:form>
	</div>